package com.itlong.cloud.sdk.service.impl;

import com.itlong.cloud.POJO.PO.BuildInfoPO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.sdk.dao.ISDKServerOldBuildDao;
import com.itlong.cloud.sdk.service.ISDKServerOldBuildService;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *
 * </desc>
 *
 * @createDate 2017/11/8
 */
@Service
public class SDKServerOldBuildServiceImpl implements ISDKServerOldBuildService {

    @Autowired
    ISDKServerOldBuildDao iSDKBuildDao;

    /**
     * <desc>
     *      根据参数字段查询build_info信息
     * <desc/>
     * @param  param  查询参数集
     * @return List<BuildInfoPO>    返回对象集
     * @author Biao.R
     * @createDate 2017/11/8
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<BuildInfoPO> getBuildByParam(Map<String, Object> param) {
        if(param.size()>0){
            return iSDKBuildDao.getBuildByParam(param);
        }
        return null;
    }

    /**
     * <desc>
     *      更新楼栋信息
     * <desc/>
     * @param   buildPO    待更新的PO对象
     * @return  Integer     更新数量
     * @author Biao.R
     * @createDate 2017/11/8
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public Integer update(BuildInfoPO buildPO) {
        try {
            if(buildPO !=null){
               return iSDKBuildDao.update(SqlUtil.durableData(buildPO, PlatformConstants.TABLE_UPDATE));
            }
        } catch (Exception e) {
            throw new DataAccessException("【SDK_build_update】更新楼栋异常",e);
        }
        return null;
    }

    /**
     * <desc>
     *      保存楼栋信息
     * <desc/>
     * @param   buildPO    待保存的PO对象
     * @return  Integer     保存数量
     * @author Biao.R
     * @createDate 2017/11/8
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public Integer save(BuildInfoPO buildPO) {
        try {
            if(buildPO !=null){
                return iSDKBuildDao.save(SqlUtil.durableData(buildPO, PlatformConstants.TABLE_SAVE));
            }
        } catch (Exception e) {
            throw new DataAccessException("【SDK_build_update】更新楼栋异常",e);
        }
        return null;
    }

    /**
     * <desc>
     *      根据楼栋编号查询楼栋ID
     * <desc/>
     * @param  params   查询参数集
     * @return  楼栋ID拼接成的字符串
     * @author Biao.R
     * @createDate 2017/11/14
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public String getBuildIdsByParams(Map<String, String> params) {
        return iSDKBuildDao.getBuildIdsByParams(params);
    }
}